package com.sunshine.domain.handler.factory;

import com.sunshine.common.enums.SubjectInfoEnum;
import com.sunshine.domain.handler.subject.subjectTypeHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @description: 题目类型处理器工厂
 * @version 1.0
 * @Author 夏百友
 * @Date 2025/11/12 19:34
 */
@Component
public class SubjectTypeHandlerFactory implements InitializingBean {


    @Resource
    private List<subjectTypeHandler> subjectTypeHandlers;


    private Map<SubjectInfoEnum,subjectTypeHandler> handlerMap = new HashMap<>();


    public subjectTypeHandler getHandler(int subjectType) {
        SubjectInfoEnum descByCode = SubjectInfoEnum.getDescByCode(subjectType);
        return handlerMap.get(descByCode);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        for (subjectTypeHandler subjectTypeHandler : subjectTypeHandlers) {
            handlerMap.put(subjectTypeHandler.getHandlerType(),subjectTypeHandler);
        }
    }
}
